#include <controls/datetimepicker/cxidatetimepicker.h>
#include <private/datetimepicker/cxidatetimepicker_p.h>
CxiDateTimePicker::CxiDateTimePicker(QWidget* parent)
	: QLineEdit(parent),
	  d_ptr(new CxiDateTimePickerPrivate(this))
{
	Q_D(CxiDateTimePicker);
	d->init();
}
CxiDateTimePicker::~CxiDateTimePicker() = default;
void CxiDateTimePicker::setDisplayFormat(const QString& format)
{
	Q_D(CxiDateTimePicker);
	d->setDisplayFormat(format);
}
QString CxiDateTimePicker::displayFormat() const
{
	Q_D(const CxiDateTimePicker);
	return d->m_format;
}
void CxiDateTimePicker::mousePressEvent(QMouseEvent* event)
{
	QLineEdit::mousePressEvent(event);// 先执行父类逻辑
	Q_D(CxiDateTimePicker);
	d->handleMousePressEvent(event);// 转发到私有类
}
void CxiDateTimePicker::wheelEvent(QWheelEvent* event)
{
	Q_D(CxiDateTimePicker);
	d->handleWheelEvent(event);// 转发到私有类
}
void CxiDateTimePicker::keyPressEvent(QKeyEvent* event)
{
	Q_D(CxiDateTimePicker);
	// 先让私有类处理自定义逻辑
	if (!d->handleKeyPressEvent(event))
	{
		// 如果未处理，则交给父类处理
		QLineEdit::keyPressEvent(event);
	}
}
void CxiDateTimePicker::setCalendarPopup(bool enable)
{
	Q_D(CxiDateTimePicker);
	d->setCalendarPopup(enable);
}
bool CxiDateTimePicker::calendarPopup() const
{
	Q_D(const CxiDateTimePicker);
	return d->calendarPopup();
}
void CxiDateTimePicker::setDateTime(const std::optional<QDateTime>& dateTime)
{
	Q_D(CxiDateTimePicker);
	d->setDateTime(dateTime);
}
std::optional<QDateTime> CxiDateTimePicker::dateTime() const
{
	Q_D(const CxiDateTimePicker);
	return d->dateTime();
}
